package com.lk.api.app;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RemoteViews;

import com.lk.api.R;

/**
 * Created by lk on 2014/12/17.
 */
public class MyNotification extends Activity {
    NotificationManager notificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_notification);
        // 设置NotificationManager NotificationManager
        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Button notification1 = (Button) findViewById(R.id.button_notification1);
        notification1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建Notification实例
                Notification notification = new Notification(R.drawable.app_sample_code, "Hi nes Manager", System.currentTimeMillis() + 3000);
                //  点击通知自动取消通知
                //  notification.flags = Notification.FLAG_AUTO_CANCEL;

                Intent intent = new Intent();
                intent.setClass(MyNotification.this, MyActivityStyle.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

                PendingIntent pendingIntent = PendingIntent.getActivity(MyNotification.this, R.drawable.ic_launcher, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                //  文本显示
                //  notification.setLatestEventInfo(MyNotification.this, "Helo World", "我是正文。。。。。", pendingIntent);

                //  震动显示 提醒更新
                notification.contentIntent = pendingIntent;
                long[] vib = {1000, 2000, 3000};
                notification.vibrate = vib;
                notification.contentView = new RemoteViews(getPackageName(), R.layout.customnotify);

                //  触发提醒
                notificationManager.notify(123, notification);

            }
        });

    }

    @Override
    protected void onStop() {
        //  停止通知
        notificationManager.cancel(123);
        //  停止通知全部
        //  notificationManager.cancelAll();
        super.onStop();
    }
}
